﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls"
                    xmlns:converters="clr-namespace:MahApps.Metro.Converters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.TextBox.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

    <Style x:Key="EditableTextBoxStyle"
           TargetType="{x:Type TextBox}"
           BasedOn="{StaticResource MetroTextBox}">
        <Setter Property="MinHeight"
                Value="26" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="enterGotFocus">
                            <DoubleAnimation Duration="0:0:0.2"
                                             To=".2"
                                             Storyboard.TargetProperty="Opacity"
                                             Storyboard.TargetName="Message" />
                        </Storyboard>
                        <Storyboard x:Key="exitGotFocus">
                            <DoubleAnimation Duration="0:0:0.2"
                                             Storyboard.TargetProperty="Opacity"
                                             Storyboard.TargetName="Message" />
                        </Storyboard>

                        <Storyboard x:Key="enterHasText">
                            <DoubleAnimation Duration="0:0:0.2"
                                             From=".2"
                                             To="0"
                                             Storyboard.TargetProperty="Opacity"
                                             Storyboard.TargetName="Message" />
                        </Storyboard>
                        <Storyboard x:Key="exitHasText">
                            <DoubleAnimation Duration="0:0:0.2"
                                             Storyboard.TargetProperty="Opacity"
                                             Storyboard.TargetName="Message" />
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Grid>
                        <Border x:Name="Base"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{TemplateBinding Background}" />
                        <Grid x:Name="PART_InnerGrid"
                              Margin="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition x:Name="ButtonColumn"
                                                  Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.ButtonWidth), Mode=OneWay}" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition x:Name="ButtonRow"
                                               Height="*" />
                            </Grid.RowDefinitions>

                            <Border x:Name="ReadOnlyVisualElement"
                                    Grid.Row="1"
                                    Grid.ColumnSpan="2"
                                    Background="{x:Null}"
                                    Opacity="0" />
                            <ScrollViewer x:Name="PART_ContentHost"
                                          Grid.Column="0"
                                          Grid.Row="1"
                                          BorderThickness="0"
                                          IsTabStop="False"
                                          Margin="2"
                                          VerticalAlignment="Stretch"
                                          Background="{x:Null}" />
                            <TextBlock x:Name="Message"
                                       Grid.Column="0"
                                       Grid.Row="1"
                                       Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
                                       Padding="{TemplateBinding Padding}"
                                       Visibility="Collapsed"
                                       Foreground="{TemplateBinding Foreground}"
                                       IsHitTestVisible="False"
                                       Opacity="0.6"
                                       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                       VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                       Margin="6,2,6,2" />
                            <Grid x:Name="FloatingMessageContainer"
                                  Grid.Column="0"
                                  Grid.ColumnSpan="2"
                                  Height="0"
                                  IsHitTestVisible="False"
                                  Margin="5,0"
                                  Visibility="Visible">
                                <TextBlock x:Name="FloatingMessage"
                                           Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
                                           FontSize="{DynamicResource FloatingWatermarkFontSize}"
                                           Foreground="{TemplateBinding Foreground}"
                                           Opacity="0.6"
                                           HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                           VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                    <TextBlock.RenderTransform>
                                        <TranslateTransform />
                                    </TextBlock.RenderTransform>
                                </TextBlock>
                            </Grid>
                            <Button x:Name="PART_ClearText"
                                    Grid.Column="1"
                                    Grid.RowSpan="2"
                                    Style="{DynamicResource ChromelessButtonStyle}"
                                     Foreground="{TemplateBinding Foreground}"
                                    FontFamily="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonFontFamily), Mode=OneWay}"
                                    Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonContent), Mode=OneWay}"
                                    Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ClearTextButton), Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
                                    Controls:TextBoxHelper.IsClearTextButtonBehaviorEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ClearTextButton), Mode=OneWay}"
                                    IsTabStop="False" />
                        </Grid>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}"
                                     Value="">
                            <Setter TargetName="Message"
                                    Property="Visibility"
                                    Value="Visible" />
                        </DataTrigger>

                        <!--Sets the MiniMessage visibility (Watermark must not be "" and FloatWatermark must be true)-->
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.HasText)}"
                                     Value="False">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource HideFloatingMessageStoryboard}" />
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource ShowFloatingMessageStoryboard}" />
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                        <!--To override Watermark == ""-->
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.Watermark)}"
                                     Value="">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource HideFloatingMessageStoryboard}" />
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource ShowFloatingMessageStoryboard}" />
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                        <!--To override TextBoxHelper.UseFloatingWatermark == false-->
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.UseFloatingWatermark)}"
                                     Value="False">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource HideFloatingMessageStoryboard}" />
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource ShowFloatingMessageStoryboard}" />
                            </DataTrigger.ExitActions>
                        </DataTrigger>

                        <!-- multiline textbox cannot bind to actual height so take the fallbach button width -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="TextWrapping"
                                           Value="NoWrap" />
                                <Condition Property="AcceptsReturn"
                                           Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ButtonColumn"
                                    Property="Width"
                                    Value="{Binding ElementName=ButtonRow, Path=ActualHeight, Mode=OneWay}" />
                        </MultiTrigger>

                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.ClearTextButton)}"
                                     Value="False">
                            <Setter TargetName="PART_ContentHost"
                                    Property="Grid.ColumnSpan"
                                    Value="2" />
                            <Setter TargetName="Message"
                                    Property="Grid.ColumnSpan"
                                    Value="2" />
                        </DataTrigger>
                        <Trigger Property="IsMouseOver"
                                 Value="True">
                            <Setter TargetName="Base"
                                    Property="BorderBrush"
                                    Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.MouseOverBorderBrush)}" />
                        </Trigger>
                        <Trigger Property="IsReadOnly"
                                 Value="True">
                            <Setter TargetName="PART_ClearText"
                                    Property="IsEnabled"
                                    Value="False" />
                            <Setter TargetName="ReadOnlyVisualElement"
                                    Property="Opacity"
                                    Value="1" />
                        </Trigger>
                        <Trigger Property="IsFocused"
                                 Value="True">
                            <Setter TargetName="Base"
                                    Property="BorderBrush"
                                    Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush)}" />
                            <Setter TargetName="FloatingMessage"
                                    Property="Foreground"
                                    Value="{DynamicResource AccentColorBrush}" />
                            <Setter TargetName="FloatingMessage"
                                    Property="Opacity"
                                    Value="1" />
                        </Trigger>
                        <Trigger SourceName="PART_ClearText"
                                 Property="IsMouseOver"
                                 Value="True">
                            <Setter TargetName="PART_ClearText"
                                    Property="Background"
                                    Value="{DynamicResource GrayBrush8}" />
                            <Setter TargetName="PART_ClearText"
                                    Property="Foreground"
                                    Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                        <Trigger SourceName="PART_ClearText"
                                 Property="IsPressed"
                                 Value="True">
                            <Setter TargetName="PART_ClearText"
                                    Property="Background"
                                    Value="{DynamicResource BlackBrush}" />
                            <Setter TargetName="PART_ClearText"
                                    Property="Foreground"
                                    Value="{DynamicResource WhiteBrush}" />
                        </Trigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="Controls:TextBoxHelper.HasText"
                                           Value="False" />
                                <Condition Property="IsFocused"
                                           Value="True" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource enterGotFocus}" />
                            </MultiTrigger.EnterActions>
                            <MultiTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource exitGotFocus}" />
                            </MultiTrigger.ExitActions>
                        </MultiTrigger>

                        <Trigger Property="Controls:TextBoxHelper.HasText"
                                 Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource enterHasText}" />
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource exitHasText}" />
                            </Trigger.ExitActions>
                        </Trigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type ComboBox}"
           x:Key="MetroComboBox">
        <Setter Property="MinHeight"
                Value="26" />
        <Setter Property="Foreground"
                Value="{DynamicResource TextBrush}" />
        <Setter Property="Background"
                Value="{DynamicResource ControlBackgroundBrush}" />
        <Setter Property="HorizontalContentAlignment"
                Value="Left" />
        <Setter Property="VerticalContentAlignment"
                Value="Center" />
        <Setter Property="BorderThickness"
                Value="1" />
        <Setter Property="Padding"
                Value="0" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="BorderBrush"
                Value="{DynamicResource TextBoxBorderBrush}" />
        <Setter Property="Controls:ControlsHelper.FocusBorderBrush"
                Value="{DynamicResource ComboBoxMouseOverInnerBorderBrush}" />
        <Setter Property="Controls:ControlsHelper.MouseOverBorderBrush"
                Value="{DynamicResource TextBoxMouseOverBorderBrush}" />
        <Setter Property="FontFamily"
                Value="{DynamicResource ContentFontFamily}" />
        <Setter Property="FontSize"
                Value="{DynamicResource ContentFontSize}" />
        <Setter Property="ItemContainerStyle"
                Value="{DynamicResource MetroComboBoxItem}" />
        <!-- change SnapsToDevicePixels to true to view a better border and validation error -->
        <Setter Property="SnapsToDevicePixels"
                Value="True" />
        <Setter Property="Validation.ErrorTemplate"
                Value="{DynamicResource ValidationErrorTemplate}" />
        <Setter Property="ScrollViewer.CanContentScroll"
                Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBox}">
                    <ControlTemplate.Resources>
                        <Storyboard x:Key="enterGotFocus">
                            <DoubleAnimation Duration="0:0:0.2"
                                             To=".2"
                                             Storyboard.TargetProperty="Opacity"
                                             Storyboard.TargetName="PART_WatermarkMessage" />
                        </Storyboard>
                        <Storyboard x:Key="exitGotFocus">
                            <DoubleAnimation Duration="0:0:0.2"
                                             Storyboard.TargetProperty="Opacity"
                                             Storyboard.TargetName="PART_WatermarkMessage" />
                        </Storyboard>

                        <Storyboard x:Key="enterHasText">
                            <DoubleAnimation Duration="0:0:0.2"
                                             From=".2"
                                             To="0"
                                             Storyboard.TargetProperty="Opacity"
                                             Storyboard.TargetName="PART_WatermarkMessage" />
                        </Storyboard>
                        <Storyboard x:Key="exitHasText">
                            <DoubleAnimation Duration="0:0:0.2"
                                             Storyboard.TargetProperty="Opacity"
                                             Storyboard.TargetName="PART_WatermarkMessage" />
                        </Storyboard>
                    </ControlTemplate.Resources>
                    <Grid>
                        <Grid.Resources>
                            <Style x:Key="comboToggleStyle"
                                   TargetType="{x:Type ToggleButton}">
                                <Setter Property="Padding"
                                        Value="3" />
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ToggleButton}">
                                            <Grid>
                                                <Border x:Name="Background"
                                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                        BorderBrush="{TemplateBinding BorderBrush}"
                                                        BorderThickness="{TemplateBinding BorderThickness}"
                                                        Background="{TemplateBinding Background}" />

                                                <Grid Margin="1">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="*" />
                                                        <ColumnDefinition Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualHeight, Mode=OneWay}" />
                                                        <ColumnDefinition Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualHeight, Mode=OneWay}" />
                                                    </Grid.ColumnDefinitions>

                                                    <Button x:Name="PART_ClearText"
                                                            Grid.Column="1"
                                                             Style="{DynamicResource ChromelessButtonStyle}"
                                                            Foreground="{TemplateBinding Foreground}"
                                                            FontFamily="Marlett"
                                                            Content="r"
                                                            Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}, Path=(Controls:TextBoxHelper.ClearTextButton), Converter={StaticResource BooleanToVisibilityConverter}}"
                                                            Controls:TextBoxHelper.IsClearTextButtonBehaviorEnabled="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}, Path=(Controls:TextBoxHelper.ClearTextButton), Mode=OneWay}"
                                                            IsTabStop="False" />
                                                    <Rectangle x:Name="BtnArrowBackground"
                                                               Grid.Column="2"
                                                               Fill="Transparent"
                                                               StrokeThickness="0" />
                                                    <Path x:Name="BtnArrow"
                                                          Grid.Column="2"
                                                          IsHitTestVisible="false"
                                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                          Data="F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z "
                                                          HorizontalAlignment="Center"
                                                          Height="4"
                                                          Stretch="Uniform"
                                                          Width="8"
                                                          Fill="{DynamicResource GrayBrush1}" />
                                                </Grid>
                                            </Grid>
                                            <ControlTemplate.Triggers>
                                                <Trigger SourceName="BtnArrowBackground"
                                                         Property="IsMouseOver"
                                                         Value="True">
                                                    <Setter TargetName="BtnArrowBackground"
                                                            Property="Fill"
                                                            Value="{DynamicResource GrayBrush5}" />
                                                </Trigger>
                                                <Trigger SourceName="PART_ClearText"
                                                         Property="IsMouseOver"
                                                         Value="True">
                                                    <Setter TargetName="PART_ClearText"
                                                            Property="Background"
                                                            Value="{DynamicResource GrayBrush8}" />
                                                    <Setter TargetName="PART_ClearText"
                                                            Property="Foreground"
                                                            Value="{DynamicResource AccentColorBrush}" />
                                                </Trigger>
                                                <Trigger SourceName="PART_ClearText"
                                                         Property="IsPressed"
                                                         Value="True">
                                                    <Setter TargetName="PART_ClearText"
                                                            Property="Background"
                                                            Value="{DynamicResource BlackBrush}" />
                                                    <Setter TargetName="PART_ClearText"
                                                            Property="Foreground"
                                                            Value="{DynamicResource WhiteBrush}" />
                                                </Trigger>
                                                <Trigger Property="IsMouseOver"
                                                         Value="True">
                                                    <Setter TargetName="Background"
                                                            Property="Background"
                                                            Value="{DynamicResource GrayBrush8}" />
                                                </Trigger>
                                                <Trigger Property="IsPressed"
                                                         Value="True">
                                                    <Setter TargetName="Background"
                                                            Property="Background"
                                                            Value="{DynamicResource GrayBrush7}" />
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Grid.Resources>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused" />
                                <VisualState x:Name="Unfocused" />
                                <VisualState x:Name="FocusedDropDown">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="00:00:00"
                                                                       Storyboard.TargetProperty="(UIElement.Visibility)"
                                                                       Storyboard.TargetName="PopupBorder">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualHeight, Mode=OneWay}" />
                                <ColumnDefinition Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualHeight, Mode=OneWay}" />
                            </Grid.ColumnDefinitions>

                            <ToggleButton x:Name="PART_DropDownToggle"
                                          Grid.ColumnSpan="3"
                                          Style="{DynamicResource comboToggleStyle}"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                          Foreground="{TemplateBinding Foreground}"
                                          BorderBrush="{TemplateBinding BorderBrush}"
                                          BorderThickness="{TemplateBinding BorderThickness}"
                                          Background="{TemplateBinding Background}"
                                          Margin="0"
                                          IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                          VerticalAlignment="Stretch"
                                          KeyboardNavigation.IsTabStop="False" />

                            <Border x:Name="EditableTextBoxBorder"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                    Visibility="Collapsed"
                                    BorderBrush="Transparent"
                                    BorderThickness="1,1,0,1"
                                    Margin="0,0,-2,0"
                                    Background="{TemplateBinding Background}">
                                <TextBox x:Name="PART_EditableTextBox"
                                         Style="{StaticResource EditableTextBoxStyle}"
                                         HorizontalAlignment="Stretch"
                                         SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                         HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                         VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                         BorderThickness="0"
                                         Background="{x:Null}"
                                         Margin="0,0,0,-2"
                                         Controls:TextBoxHelper.Watermark="{TemplateBinding Controls:TextBoxHelper.Watermark}"
                                         MaxLength="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ComboBoxHelper.MaxLength), Mode=OneWay}"
                                         CharacterCasing="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ComboBoxHelper.CharacterCasing), Mode=OneWay}"
                                         Foreground="{TemplateBinding Foreground}"
                                         Focusable="True"
                                         IsReadOnly="{TemplateBinding IsReadOnly}"
                                         FontFamily="{TemplateBinding FontFamily}"
                                         FontSize="{TemplateBinding FontSize}" />
                            </Border>
                            <TextBlock x:Name="PART_WatermarkMessage"
                                       Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
                                       Padding="{TemplateBinding Padding}"
                                       Visibility="Collapsed"
                                       Foreground="{TemplateBinding Foreground}"
                                       IsHitTestVisible="False"
                                       Opacity="0.6"
                                       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                       VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                       FontFamily="{TemplateBinding FontFamily}"
                                       FontSize="{TemplateBinding FontSize}"
                                       Margin="8,2,4,2" />
                            <Grid x:Name="ContentSite"
                                  Margin="7 0 0 0">
                                <ContentPresenter ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
                                                  ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                                  Content="{TemplateBinding SelectionBoxItem}"
                                                  ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  IsHitTestVisible="False"
                                                  Margin="{TemplateBinding Padding}"
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                            </Grid>
                        </Grid>

                        <Border x:Name="FocusBorder"
                                Grid.ColumnSpan="3"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{x:Null}"
                                Visibility="Collapsed" />
                        <Border x:Name="DisabledVisualElement"
                                Grid.ColumnSpan="3"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                BorderBrush="{DynamicResource ControlsDisabledBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{DynamicResource ControlsDisabledBrush}"
                                Opacity="0.6"
                                IsHitTestVisible="False"
                                Visibility="Collapsed" />

                        <!-- AllowsTransparency="true" fixes the redraw problem under windows vista/7 with a selected non aero theme -->
                        <Popup x:Name="PART_Popup"
                               AllowsTransparency="True"
                               Focusable="False"
                               IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
                               PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"
                               Placement="Bottom">
                            <Grid MinWidth="{Binding ActualWidth, RelativeSource={RelativeSource TemplatedParent}}"
                                  MaxHeight="{Binding MaxDropDownHeight, RelativeSource={RelativeSource TemplatedParent}}">
                                <Border x:Name="PopupBorder"
                                        Effect="{DynamicResource DropShadowBrush}"
                                        BorderThickness="{TemplateBinding BorderThickness}"
                                        HorizontalAlignment="Stretch"
                                        Height="Auto"
                                        BorderBrush="{DynamicResource ComboBoxPopupBrush}"
                                        Background="{DynamicResource WhiteBrush}">
                                </Border>
                                <ScrollViewer x:Name="DropDownScrollViewer"
                                              BorderThickness="0"
                                              Margin="2"
                                              Padding="1">
                                    <ItemsPresenter x:Name="ItemsPresenter"
                                                    KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                            </Grid>
                        </Popup>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEditable}"
                                           Value="False" />
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem}"
                                           Value="{x:Null}" />
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="PART_WatermarkMessage"
                                    Property="Visibility"
                                    Value="Visible" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem, Mode=OneWay, Converter={x:Static converters:IsNullConverter.Instance}}"
                                           Value="True" />
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsKeyboardFocusWithin}"
                                           Value="True" />
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEditable}"
                                           Value="False" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource enterGotFocus}" />
                            </MultiDataTrigger.EnterActions>
                            <MultiDataTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource exitGotFocus}" />
                            </MultiDataTrigger.ExitActions>
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem, Mode=OneWay, Converter={x:Static converters:IsNullConverter.Instance}}"
                                           Value="False" />
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEditable}"
                                           Value="False" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.EnterActions>
                                <BeginStoryboard Storyboard="{StaticResource enterHasText}" />
                            </MultiDataTrigger.EnterActions>
                            <MultiDataTrigger.ExitActions>
                                <BeginStoryboard Storyboard="{StaticResource exitHasText}" />
                            </MultiDataTrigger.ExitActions>
                        </MultiDataTrigger>

                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.ClearTextButton)}"
                                     Value="False">
                            <Setter TargetName="EditableTextBoxBorder"
                                    Property="Grid.ColumnSpan"
                                    Value="2" />
                            <Setter TargetName="ContentSite"
                                    Property="Grid.ColumnSpan"
                                    Value="2" />
                        </DataTrigger>
                        <Trigger Property="IsEditable"
                                 Value="True">
                            <Setter Property="IsTabStop"
                                    Value="false" />
                            <Setter TargetName="EditableTextBoxBorder"
                                    Property="Visibility"
                                    Value="Visible" />
                            <Setter TargetName="ContentSite"
                                    Property="Visibility"
                                    Value="Hidden" />
                            <Setter TargetName="PART_DropDownToggle"
                                    Property="Focusable"
                                    Value="False" />
                            <!-- #1037 : don't know why we set this to transparent ???
                            <Setter TargetName="PART_DropDownToggle"
                                    Property="Background"
                                    Value="Transparent" /> -->
                        </Trigger>

                        <Trigger Property="IsMouseOver"
                                 Value="True">
                            <Setter TargetName="FocusBorder"
                                    Property="Visibility"
                                    Value="Visible" />
                            <Setter TargetName="FocusBorder"
                                    Property="BorderBrush"
                                    Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.MouseOverBorderBrush)}" />
                        </Trigger>

                        <Trigger SourceName="PART_EditableTextBox"
                                 Property="IsFocused"
                                 Value="True">
                            <Setter TargetName="FocusBorder"
                                    Property="Visibility"
                                    Value="Visible" />
                            <Setter TargetName="FocusBorder"
                                    Property="BorderBrush"
                                    Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush)}" />
                        </Trigger>
                        <Trigger Property="IsFocused"
                                 Value="True">
                            <Setter TargetName="FocusBorder"
                                    Property="Visibility"
                                    Value="Visible" />
                            <Setter TargetName="FocusBorder"
                                    Property="BorderBrush"
                                    Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush)}" />
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin"
                                 Value="True">
                            <Setter TargetName="FocusBorder"
                                    Property="Visibility"
                                    Value="Visible" />
                            <Setter TargetName="FocusBorder"
                                    Property="BorderBrush"
                                    Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush)}" />
                        </Trigger>

                        <Trigger Property="IsEnabled"
                                 Value="False">
                            <Setter TargetName="DisabledVisualElement"
                                    Property="Visibility"
                                    Value="Visible" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="VirtualisedMetroComboBox"
           TargetType="{x:Type ComboBox}"
           BasedOn="{StaticResource MetroComboBox}">
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel IsItemsHost="True"
                                            KeyboardNavigation.DirectionalNavigation="Contained"
                                            IsVirtualizing="True"
                                            VirtualizationMode="Recycling" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ScrollViewer.CanContentScroll"
                Value="True" />
        <Style.Triggers>
            <Trigger Property="IsGrouping"
                     Value="True">
                <Setter Property="ScrollViewer.CanContentScroll"
                        Value="False" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="ComboBoxItem"
           x:Key="MetroComboBoxItem">
        <Setter Property="Foreground"
                Value="{DynamicResource TextBrush}" />
        <Setter Property="Padding"
                Value="2" />
        <Setter Property="HorizontalContentAlignment"
                Value="Left" />
        <Setter Property="VerticalContentAlignment"
                Value="Top" />
        <Setter Property="RenderOptions.ClearTypeHint"
                Value="Enabled" />
        <Setter Property="Background"
                Value="{DynamicResource WhiteBrush}" />
        <Setter Property="BorderThickness"
                Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBoxItem">
                    <Grid Background="{TemplateBinding Background}"
                          Margin="0,0.5">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver" />
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"
                                                                       Storyboard.TargetName="contentPresenter">
                                            <SplineDoubleKeyFrame KeyTime="0"
                                                                  Value=".55" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="ItemBackground"
                                IsHitTestVisible="False"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                Background="{TemplateBinding Background}" />
                        <ContentPresenter x:Name="contentPresenter"
                                          TextElement.Foreground="{TemplateBinding Foreground}"
                                          Margin="{TemplateBinding Padding}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected"
                                 Value="True">
                            <Setter TargetName="ItemBackground"
                                    Property="Background"
                                    Value="{DynamicResource AccentColorBrush}" />
                            <Setter Property="Foreground"
                                    Value="{DynamicResource AccentSelectedColorBrush}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver"
                                 Value="True">
                            <Setter TargetName="ItemBackground"
                                    Property="Background"
                                    Value="{DynamicResource AccentColorBrush2}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
